Imports System.Collections.ObjectModel
Imports System.Collections.Generic

Public Class RankingPalavras
    Inherits KeyedCollection(Of String, Palavra)

    Public Sub New()
        MyBase.New()
    End Sub

    Protected Overrides Function GetKeyForItem( _
        ByVal item As Palavra) As String
        Return item.palavra
    End Function

    Public Enum Ordenacao
        FrequenciaCrescente
        FrequenciaDecrescente
    End Enum

    Public Function GetSortedList(ByVal sorter As Ordenacao) As List(Of Palavra)
        Dim temp As New List(Of Palavra)(MyBase.Items)
        Select Case sorter
            Case Ordenacao.FrequenciaDecrescente
                temp.Sort(New PalavraFrequenciaSorterDesc)
        End Select
        Return temp
    End Function

    Private Class PalavraFrequenciaSorterDesc
        Implements IComparer(Of Palavra)

        Function Compare(ByVal x As SumarizadorEngine.Palavra, ByVal y As SumarizadorEngine.Palavra) As Integer Implements IComparer(Of Palavra).Compare

            If x.frequencia > y.frequencia Then
                Return -1
            ElseIf x.frequencia = y.frequencia Then
                Return 0
            ElseIf x.frequencia < y.frequencia Then
                Return 1
            End If
        End Function
    End Class

End Class
